Ext.require([
   'Ext.form.*',
   'Ext.tip.*',
   'Ext.form.field.Text',
   'Ext.tip.QuickTipManager',
   'Ext.window.Window',
   'Ext.data.Field',
   'Ext.layout.container.Column',
]);

function formulario_login(){
	
	Ext.onReady(function() {
		
		
		
		var win = Ext.create('Ext.window.Window', {
			title: 'Acceso a PDM',     
			width: 300,
			heigth: 150,
			minimizable: true,
			maximizable: true,   
			closable: false, 
			//draggable: false,
			border: false,                    
			items:[
			{
				id: "formulario",
				xtype: "form",
				bodyStyle:'background-color:#fff;padding: 20px', 
				
				items: [
				{
					xtype: 'textfield',
					name: 'login',
					fieldLabel: 'Usuario',
					width: "100%",
					allowblank: false
				},
				{
					xtype: 'textfield',
					name: 'password',
					fieldLabel: 'Contraseña',
					width: "100%",
					inputType: "password",
					allowblank: false
					
				}],
				buttons: [
				{
					text: 'Acceder',
					handler: function(){
						Ext.getCmp("formulario").getForm().submit({
							url: "/login",
							params: {
								submit: "submit"
							},
							method: "post",
							waitTitle:'Conectando', 
							waitMsg:'Enviando datos...',
							success: function() {							
								win.close();												
								
								base= 'index', 
								window.location = base;
																																																																																																					
							},
							failure: function() {
								Ext.Msg.alert("Error", "Solicite su registro al administrador del sistema");
							}	
						})
					}
				 }]
			}]
		});
		win.show();    
	});
}

function formulario_add_usuario(){
	
	Ext.onReady(function() {
		
		
		
		var win = Ext.create('Ext.window.Window', {
			title: 'nuevo usuario',     
			width: 300,
			heigth: 150,
			minimizable: true,
			maximizable: true,   
			closable: false, 
			//draggable: false,
			border: false,                    
			items:[
			{
				id: "formulario",
				xtype: "form",
				bodyStyle:'background-color:#fff;padding: 20px', 
				
				items: [
				{
					xtype: 'textfield',
					name: 'usuario',
					fieldLabel: 'Usuario',
					width: "100%",
					allowblank: false
				},
				{
					xtype: 'textfield',
					name: 'password',
					fieldLabel: 'Contraseña',
					width: "100%",
					inputType: "password",
					allowblank: false
					
				},
				{
					xtype: 'textfield',
					name: 'confirmar_password',
					fieldLabel: ' Repita Contraseña',
					width: "100%",
					inputType: "password",                                                     
					allowblank: false
					
				},
				{
					xtype: 'textfield',
					name: 'nombre_usuario',
					fieldLabel: 'Nombre',
					width: "100%",
					allowblank: false
				},
				{
					xtype: 'textfield',
					name: 'apellido',
					fieldLabel: 'Apellido',
					width: "100%",
					allowblank: false
				},
				{
					xtype: 'textfield',
					name: 'email',
					fieldLabel: 'Email',
					vtype:'email',
					width: "100%",
					allowblank: false
				},
				{
					xtype: 'textfield',
					name: 'telefono',
					fieldLabel: 'Telefono',
					width: "100%",
					allowblank: false
				}],
				buttons: [
				{
					text: 'Acceder',
					handler: function(){
						Ext.getCmp("formulario").getForm().submit({
							url: "/add_usuario",
							params: {
								submit: "submit"
							},
							method: "post",
							waitTitle:'Conectando', 
							waitMsg:'Enviando datos...',
							success: function() {							
								win.close();												
								
								base= 'index', 
								window.location = base;
																																																																																																					
							},
							failure: function() {
								Ext.Msg.alert("Error", "No se pudo almacenar el usuario");
							}	
						})
					}
				 }]
			}]
		});
		win.show();    
	});
}
